import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  // 文件路径：src/store/index.js
state: {

 
  isLogin: 0,  // 判断用户是否登陆
  userNick: '',	
  
  // 模拟数据库用户信息
  testInfo: [
    {
      account: 'bjpengyuyan',
      password: '111111',
      userNick: '滨江彭于晏',

      likeList: ['健身', '台球']
    }
  ]
},
// 通过用户名获取用户信息，在登陆验证时会用到
getters: {
  testUserInfo: state => account => {
    let userinfoIndex = state.testInfo.findIndex(info => info.account === account)
    return userinfoIndex === -1 ? undefined : state.testInfo[userinfoIndex]
  }
},

  mutations: {
    loginOut(state) {
      state.isLogin = 0
      state.userNick = ''
      
    },
    loginIn(state, payload) {
      state.isLogin = 1
      state.userNick = payload.userNick
     
    },
    register: (state, payload) => state.testInfo.push(payload)
  },
  actions: {
  },
  modules: {
  }
})
